import com.mysql.jdbc.Connection;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class APP {
    public static void main(String[] args) throws SQLException {
        //1.获取datasource
        MysqlDataSource mysqlDataSource=new MysqlDataSource();
        mysqlDataSource.setURL("jdbc:mysql://127.0.0.1:3306/java33?characterEncoding=utf-8&&useSSL=true");
        mysqlDataSource.setUser("root");
        mysqlDataSource.setPassword("12345678");

        //2.得到连接
        Connection connection= (Connection) mysqlDataSource.getConnection();

        //3.拼接sql并执行
        PreparedStatement statement = connection.prepareStatement("select * from student");

        //4.执行查询
        ResultSet resultSet=statement.executeQuery();
        while(resultSet.next()){
            System.out.println("用户名："+resultSet.getString("username"));
            System.out.println("email:"+resultSet.getString("mail"));
        }
        //5.关闭资源
        resultSet.close();
        connection.close();
    }
}
